<template>
  <div>
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <van-card
        v-for="(item, i) in GoodsList"
        :key="i"
        :price="item.goods_price"
        :title="item.goods_name"
        :thumb="item.goods_small_logo"
        @click="handleCard(item.goods_id)"
      />
    </van-list>
  </div>
</template>
<script>
import { request1 } from "../../network/request";

export default {
  props: ["category_id"],
  data() {
    return {
      GoodsList: [],
      activeName: "a",

      list: [],
      loading: false,
      finished: false,
    };
  },
  created() {
    request1({
      url: "/goods/search?cid=" + this.category_id,
    }).then((res) => {
      this.GoodsList = res.message.goods;
    });
  },
  methods: {
    handleCard(id) {
      this.$router.push({
        name: "goods_info",
        params: {
          id: id,
        },
      });
    },
    onLoad() {
      // 异步更新数据
      // setTimeout 仅做示例，真实场景中一般为 ajax 请求
      setTimeout(() => {
        for (let i = 0; i < 10; i++) {
          this.list.push(this.list.length + 1);
        }

        // 加载状态结束
        this.loading = false;

        // 数据全部加载完成
        if (this.list.length >= 40) {
          this.finished = true;
        }
      }, 1000);
    },
  },
};
</script>
<style scoped></style>
